home *** CD-ROM | disk | FTP | other *** search
Wrap
#! /usr/bin/perl5 # # sendmail-conf.cgi # # Copyright 1988-1996 Silicon Graphics, Inc. # All rights reserved. # # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.; # the contents of this file may not be disclosed to third parties, copied or # duplicated in any form, in whole or in part, without the prior written # permission of Silicon Graphics, Inc. # # RESTRICTED RIGHTS LEGEND: # Use, duplication or disclosure by the Government is subject to restrictions # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data # and Computer Software clause at DFARS 252.227-7013, and/or in similar or # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished - # rights reserved under the Copyright Laws of the United States. # # $Id: sendmail-conf.frm,v 1.25 1997/06/19 22:25:50 shotes Exp $ BEGIN { require "/usr/WebFace/lib/CGI.pm"; import CGI; } require "/usr/OnRamp/lib/OnRamp.pm"; require "/usr/OnRamp/lib/java.pm"; require "flush.pl"; $query = new CGI; $cmd = "/usr/etc/configmail"; $prm = "/etc/sendmail.params"; $tmpprm = "/etc/sendmail.params.tmp"; $MAILSCRIPT = "/etc/init.d/mail"; $title = "Sendmail Configuration"; if ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla\/2/) { $br_index = 1; } else { $br_index = 0; } $js = "$js_check_int which = \"none\"; br_index = $br_index; function runSubmit() { // onClick gets processed before onSubmit if(which == \"ok\") return runOK(); return (true); } function markOK() { which = \"ok\"; } function markOther() { which = \"none\"; } function runOK() { form = document.SendmailForm; if (form.enable[br_index].checked) { // radio buttons are backwards if (!testHostname(form.forwarder,\"forwarding host name\")) return (false); if (!testHostname(form.rootdomain,\"root domain name\")) return (false); if (!testHostname(form.relayname,\"relay host name\")) return (false); if (!testHostname(form.localdomain,\"local domain name\")) return (false); if (!testDirectory(form.pathalias)) return (false); if (!testHostList(form.directdomains)) return (false); } return (true); } function testDirectory(Ctrl) { word = Ctrl.value; if (word == \"\") { errorBox (Ctrl, \"The UUCP path-alias directory is required.\\nTo disable the path-alias database, enter \\n/dev/null as the directory.\"); Ctrl.value = \"/dev/null\"; return (false); } for(i = 0; i < word.length; i++) { if (word.charAt(i) == ' ') { errorBox (Ctrl, \"The UUCP directory cannot \\ncontain spaces.\"); return (false); } } if (word.charAt(0) != '/') { errorBox (Ctrl, \"The UUCP directory must be \\nfully qualified.\"); return (false); } return (true); } function testHostname(Ctrl,what) { if (Ctrl.value == \"\") { errorBox (Ctrl, \"The \" + what + \" is required.\"); return (false); } error = testHost(Ctrl.value); if (error == 1) { errorBox (Ctrl, \"The \" + what + \" cannot \\ncontain \" + illegal + \" characters.\"); return (false); } if (error == 2) { errorBox (Ctrl, \"The \" + what + \" cannot start or \\n end with a . or - or _ character.\"); return (false); } if (error == 3) { errorBox (Ctrl, \"The \" + what + \" cannot contain \\nconsecutive . or - or _ characters.\"); return (false); } if (error == 4) { errorBox (Ctrl, \"The \" + what + \" cannot contain spaces.\"); return (false); } if (error == 5) { errorBox (Ctrl, \"The \" + what + \" cannot begin \\nwith a number.\"); return (false); } return (true); } function testHostList(Ctrl) { whitespace = \" \\n\\r\\t\\f\"; space = true; for(start=0, cur=0; cur < Ctrl.value.length; cur++) { for(i = 0; i < whitespace.length; i++) { c = whitespace.charAt(i); if (Ctrl.value.charAt(cur) == c) { // found whitespace if (space == false) { space = true; if(cur != start) { host = Ctrl.value.substring(start,cur); if (testHost(host)) { errorBox (Ctrl, \"Invalid relay host name: \" + host); return (false); } } } break; } else { // found character if (space == true) { space = false; start = cur; } } } } if(cur != start && space == false) { host = Ctrl.value.substring(start,cur); if (testHost(host)) { errorBox (Ctrl, \"Invalid relay host name: \" + host); return (false); } } return (true); } function testHost(word) { metaChars = \"{}()*!~<>?|[]'&^\$\@\#`\\\";:\\\\/+=,%\"; start = 0; while (word.charAt(start) == ' ') { start++; } end = word.length-1; while (word.charAt(end) == ' ') { end--; } for(j = 0; j < metaChars.length; j++) { c = metaChars.charAt(j); i = word.indexOf(c, 0); if (i != -1) { illegal = c; return 1; } } sch = word.charAt(start); ech = word.charAt(end); if(sch == '.' || sch == '-' || sch == '_') return 2; if(ech == '.' || ech == '-' || ech == '_') return 2; for(j = start; j <= end; j++) { ch = word.charAt(j); if (ch == '.' || ch == '-' || ch == '_') { if (word.charAt(j+1) == ch) return 3; } if (ch == ' ') { return 4; } } if(checkInt_c(sch, 10)) return 5; return 0; } function errorBox (Ctrl, ErrorMessage) { alert (ErrorMessage); Ctrl.focus(); return; }"; @supported = ( 'forwarder', 'rootdomain', 'relayname', 'localdomain', 'pathalias', 'directdomains' ); print $query->header; &getValues; if ($query->param) { $help = $document_root . $ENV{"SCRIPT_NAME"}; $help =~ s/cgi$/hlp/; exec $help if ($query->param('help') eq "Help"); if ($query->param('doit') eq 'Ok') { if ($query->param('enable') eq 'Yes') { &formValidation; } if ($hash{'enable'} ne $query->param('enable')) { if ($query->param('enable') eq 'Yes') { system("/etc/chkconfig", "sendmail", "on"); $message = "Sendmail enabled."; } else { system("/etc/chkconfig", "sendmail", "off"); $message = "Sendmail disabled."; } &flush(stdout); if (!fork) { system($MAILSCRIPT, "stop"); system($MAILSCRIPT, "start"); exit 0; } } if ($query->param('enable') eq 'Yes') { undef %fileList; open(PRM, "< $prm"); while(<PRM>) { chomp(); ($left,$right) = split(/:/); if ($left && $right) { $fileList{$left} = $right; } } close(PRM); $mod = 0; foreach $arg (@supported) { $vals{$arg} = $query->param($arg) } foreach $arg (keys(%vals)) { if ($vals{$arg} ne $hash{$arg}) { $mod = 1; $fileList{$arg} = $vals{$arg}; } } if ($mod == 1) { open(PRMT, ">$tmpprm"); foreach $arg (keys(%fileList)) { print PRMT "$arg:$fileList{$arg}\n"; } close(PRMT); rename($tmpprm, $prm); system($MAILSCRIPT, "start"); $message .= " Configuration file updated."; } } } if (!$message) { $message = "No changes made."; } } $NSstatus = &checkForNS; if ($NSstatus) { &title_block($title); &header_block($title); print "<i>NS Mail is currently running. To enable sendmail, first disable NS Mail.</i>"; } else { &generic; } exit 0; sub checkForNS { local($mail_process) = "NscpMail"; local($ret) = 0; open(PSNS, "/bin/ps -ef |"); while(<PSNS>) { if ($_ =~ m:$mail_process:) { $ret = 1; } } close(PSNS); $ret; } sub error { &error_block($_[0]); &generic; exit 0; } sub getValues { $hash{'enable'} = &get_config("sendmail"); open(LIST, "$cmd list |"); @configlist = <LIST>; close(LIST); for ($i = 0; $i < $#configlist; $i++) { $configlist[$i] =~ s/[\"\s+]//g; ($attr, $aval) = split(/=/, $configlist[$i]); if ($attr ne "") { $hash{$attr} = $aval; chop($aval); } } $hash{'directdomains'} =~ s/,/\n/g; } sub formValidation { my $error; $error = &check_hostname($query->param('forwarder')); &error("Forwarding host name cannot contain shell metacharacters") if $error == 911; &error("Invalid forwarding host name") if $error; $localDomain = $query->param('localdomain'); &error("Invalid local domain name.") if (!$localDomain || &check_hostname($localDomain)); $error = &check_hostname($query->param('rootdomain')); &error("Root domain name cannot contain shell metacharacters") if $error == 911; &error("Invalid root domain name") if $error; my $directs = $query->param('directdomains'); $directs =~ s/[\n\s]+/,/g; $directs =~ s/(^,)+|(,$)//g; foreach (split(/,/,$directs)) { &error(qq|Invalid relay hostname "$_"|) if &check_hostname($_); } $query->param('directdomains', $directs); &error("UUCP path-alias database directory must already exist") if ! -d $query->param('pathalias') && $query->param('pathalias') ne '/dev/null'; $error = &check_hostname($query->param('relayname')); &error("Relay host name cannot contain shell metacharacters") if $error == 911; &error("Invalid relay host name") if $error; } sub generic { &js_title_block($title,$js); &header_block($title); print "<i>$message</i>"; print $query->startform("POST", "", "", "NAME=SendmailForm", "onSubmit=\"return runSubmit(this.form)\""); print "<center><table cellpadding=5 width=450>\n"; print "<tr><th align=left>Enable sendmail:</th><th align=left>", $query->radio_group(-name=>'enable', -values=>['Yes','No'], -default=>$hash{'enable'}),"</th></tr>"; print "<tr><th align=left>Hostname of mail forwarder:</th>\n", "<th align=left>", $query->textfield(-name=>'forwarder', -default=>$hash{"forwarder"}, -size=>20, -maxlength=>256), "</th></tr>"; print "<tr><th align=left>Root domain name:</th>\n", "<th align=left>", $query->textfield(-name=>'rootdomain', -default=>$hash{"rootdomain"}, -size=>20, -maxlength=>256), "</th></tr>"; print "<tr><th align=left>Hostname of mail relay:</th>\n", "<th align=left>", $query->textfield(-name=>'relayname', -default=>$hash{"relayname"}, -size=>20, -maxlength=>256), "</th></tr>"; print "<tr><th align=left>Local domain name:</th>\n", "<th align=left>", $query->textfield(-name=>'localdomain', -default=>$hash{"localdomain"}, -size=>20, -maxlength=>256), "</th></tr>"; print "<tr><th align=left>Directory of the UUCP path-alias database:</th>\n", "<th align=left>", $query->textfield(-name=>'pathalias', -default=>$hash{"pathalias"}, -size=>20, -maxlength=>256), "</th></tr>"; print "<tr><th align=left valign=top>List of domains for which this host is the relay:</th>\n", "<th align=left>"; $fix = $query->param('directdomains'); $fix =~ s/,/\n/g; $query->param('directdomains',$fix); print $query->textarea(-name=>'directdomains', -rows=>4, -default=>$hash{"directdomains"}), "</th></tr>"; print "</table></center><br>"; print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"'); print $query->endform; }